<template>
	<view class="content" style="padding-top: 0upx; ">
		<view>
			<!-- 搜索框 -->
			<jshopsearch></jshopsearch>
			<!-- 这里是轮播图 -->
			<jshopimgSlide></jshopimgSlide>
			<!-- 分期值商品   抢购区商品 -->
			<installmentgoods></installmentgoods>
			<!-- 商品组名称 -->
			<jshopgoods :jdata="pageData.list"></jshopgoods>
			<view class="loading">{{loadingText}}</view>
		</view>
		<!-- <home :jdata="pageData"></home> -->

		<!-- #ifdef H5 || APP-PLUS-NVUE || APP-PLUS -->
		<view class="service" @click="showChat()">
			<image class="icon" src="/static/image/seller-content.png" mode=""></image>
		</view>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->
		<button class="service" hover-class="none" open-type="contact" bindcontact="showChat" :session-from="kefupara">
			<image class="icon" src="/static/image/seller-content.png" mode=""></image>
		</button>
		<!-- #endif -->
	</view>
</template>
<script>
	import jshopimgSlide from '@/components/home/jshop-imgSlide.vue'
	import jshopsearch from '@/components/home/jshop-search.vue'
	import jshopgoods from '@/components/home/jshop-goods.vue'
	import installmentgoods from '@/components/home/installment-goods.vue'

	// import home from '@/components/home/home.vue';
	import {
		goods
	} from '@/config/mixins.js';
	import {
		goBack
	} from '@/config/mixins.js';
	import datas from '@/common/data.js';
	import BaseUrl from '@/config/syapi.js';
	export default {
		mixins: [goods],
		components: {
			// home,
			jshopimgSlide,
			jshopsearch,
			jshopgoods,
			installmentgoods
		},
		data() {
			return {
				imageUrl: '/static/image/share_image.png', //店铺分享图片
				pageCode: 'mobile_home', //页面布局编码
				pintuan: [], //拼团列表,
				redBagShow: false, //红包
				config: '', //配置信息
				userInfo: {}, // 用户信息
				kefupara: '', //客服传递资料
				copy: false,
				suTipStatus: false,
				shareUrl: '/pages/share/jump',
				pageData: {
					"totalCount": 0, // 当前返回的数据数量
					"pageSize": 10, // 每页显示多少
					"totalPage": 1, // 
					"currPage": 1, // 当前页码
					"list": []
				},
				loadingText: '加载中...',
				page: {
					limit: 1,
					page: 1
				}
			};
		},
		updated() {
			this.copy = true;
		},
		computed: {

		},
		onLoad(e) {
			this.initData();
		},
		onShow() {
			// this.datas.pageData
			// #ifdef MP-WEIXIN
			this.userIsSubscription();
			// #endif
		},
		created() {
			console.log('this.datas.pageData', datas) // 得到daily里面的数据
		},
		onReachBottom() { // 下拉触底
			// 下拉获取数据
			this.initData();
			// 让商品列表的视图，上调一点点，用来解决下拉触底无法触发的问题
			uni.pageScrollTo({
				scrollTop: this.scrollTop - 15
			});
		},
		onPageScroll(e) { // 监听页面的高度
			this.scrollTop = e.scrollTop;

		},
		methods: {
			destroyed() {
				window.removeEventListener('scroll', this.handleScroll);
			},
			goSearch() {
				uni.navigateTo({
					url: './search'
				});
			},
			// 首页初始化获取数据
			initData() {
				//获取首页配置
				// this.pageData = datas;
				// setTimeout(() => {
				// 	this.showLoad = false;
				// }, 600)
				// 原
				// uni.request({
				// 	url: BaseUrl.StagingList,
				// 	header: {
				// 		'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
				// 		'token': this.$db.get('userToken')
				// 	},
				// 	data: {

				// 	},
				// 	success: res => {
				// 		if (res.statusCode == 200) {
				// 			console.log('res.data.list', res.data.data.list)
				// 			// this.byStages=res.data.list
				// 		}
				// 	}
				// })
				// 显示加载提示框
				uni.showLoading();

				let _this = this;
				// 获取首页列表数据
				uni.request({
					url: BaseUrl.shopList,
					method: "GET",
					data: {
						"limit": this.page.limit,
						"page": this.page.page
					},
					success: res => {
						if (res.statusCode == 200) {
							uni.hideLoading(); // 隐藏加载框
							// console.log('res.data.list', res.data.data.list)
							// this.byStages=res.data.list
							if (res.data.data.list.length > 0) { //还有数据的情况
								this.loadingText = '';
								this.pageData.list.push(...res.data.data.list);
								this.page.page++; //页码+1
							} else {
								this.loadingText = '已经没有更多了';
							}
						}
					}
				})


				// this.$api.getPageConfig(
				// 	{
				// 		code: this.pageCode
				// 	},
				// 	res => {
				// 		if (res.status == true) {
				// 			console.log("this.pageData",this.pageData)
				// 			//隐藏loading
				// 			;
				// 		}
				// 	}
				// );

				//判断是开启分销还是原始推广
				// this.$api.shopConfig(res => {
				// 	this.config = res;
				// });

				// 判断是否登陆
				// var _this = this;
				// if (this.$db.get('userToken')) {
				// 	this.$api.userInfo({}, res => {
				// 		if (res.status) {
				// 			_this.userInfo = res.data;
				// 			// #ifdef MP-WEIXIN
				// 			//微信小程序打开客服时，传递用户信息
				// 			var kefupara = {};
				// 			kefupara.nickName = res.data.nickname;
				// 			kefupara.tel = res.data.mobile;
				// 			_this.kefupara = JSON.stringify(kefupara);
				// 			// #endif
				// 		}
				// 	});
				// } else {
				// 	this.$common.navigateTo('/pages/login/login/index1');
				// }

				// #ifdef MP-WEIXIN
				this.userIsSubscription();
				// #endif

				// this.getShareUrl();
			},
			//在线客服,只有手机号的，请自己替换为手机号
			showChat() {
				// #ifdef H5
				let _this = this;
				window._AIHECONG('ini', {
					entId: this.config.ent_id,
					button: false,
					appearance: {
						panelMobile: {
							tone: '#FF7159',
							sideMargin: 30,
							ratio: 'part',
							headHeight: 50
						}
					}
				});
				//传递客户信息
				window._AIHECONG('customer', {
					head: _this.userInfo.avatar,
					名称: _this.userInfo.nickname,
					手机: _this.userInfo.mobile
				});
				window._AIHECONG('showChat');
				// #endif

				// 客服页面
				// #ifdef APP-PLUS || APP-PLUS-NVUE
				this.$common.navigateTo('../customer_service/index');
				// #endif

				// 头条系客服
				// #ifdef MP-TOUTIAO
				if (this.shopMobile != 0) {
					let _this = this;
					tt.makePhoneCall({
						phoneNumber: this.shopMobile.toString(),
						success(res) {},
						fail(res) {}
					});
				} else {
					_this.$common.errorToShow('暂无设置客服电话');
				}
				// #endif
			},

			//获取分享URL
			// getShareUrl() {
			//     let data = {
			//         client: 2,
			//         url: "/pages/share/jump",
			//         type: 1,
			//         page: 1,
			//     };
			//     let userToken = this.$db.get('userToken');
			//     if (userToken && userToken != '') {
			//     	data['token'] = userToken;
			//     }
			//     this.$api.share(data, res => {
			//         this.shareUrl = res.data
			//     });
			// }
		},
		onPullDownRefresh() {
			this.initData();
			uni.stopPullDownRefresh();
		},
		//分享

		// #ifdef MP-WEIXIN || APP-PLUS || APP-PLUS-NVUE
		// onPageScroll() {
		// 	var _this = this;
		// 	const query = uni.createSelectorQuery();
		// 	query
		// 		.select('.content >>> .search')
		// 		.boundingClientRect(function(res) {
		// 			if (res) {
		// 				if (res.top < 0) {
		// 					_this.$store.commit('searchFixed', true);
		// 				} else {
		// 					_this.$store.commit('searchFixed', false);
		// 				}
		// 			}
		// 		})
		// 		.exec();
		// }
		//#endif
	};
</script>

<style>
	.jshop {
		background-color: #F5F5F5;
	}

	.content {}

	.cell-item {
		border: none;
	}

	.cell-ft-text {
		font-size: 22upx;
		color: #999;
	}

	.service {
		width: 80rpx;
		height: 80rpx;
		background-color: #fff;
		border-radius: 50%;
		position: fixed;
		right: 30rpx;
		bottom: 120rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		box-shadow: 0 0 10rpx #ccc;
		padding: 0;
		z-index: 996;
	}

	.service .icon {
		width: 60rpx;
		height: 60rpx;
	}

	.subscription-notice {
		background-color: #ffffff;
		box-shadow: 0 2rpx 18rpx #eeeeee;
		position: relative;
		z-index: 99;
		height: 66rpx;
		line-height: 66rpx;
		padding: 0 20rpx;
		font-size: 28rpx;
		color: #333333;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.subscription-notice>view {
		display: flex;
		align-items: center;
	}

	.subscription-notice .icon {
		width: 32rpx;
		height: 32rpx;
		margin-right: 10rpx;
	}

	.subscription-notice-btn {
		color: #4285f4;
	}

	.subscription-notice-btn-close {
		color: #888888;
		padding-left: 10px;
		font-size: 30rpx;
	}

	.loading {
		text-align: center;
		line-height: 80px;
	}
</style>
